/**
* @author AlbertDarren
* @contact 2563491540@qq.com
*/
#include <iostream>
#include <map>
#include <string>
using namespace std;

int main_25()
{
    map<int,string> m;
    multimap<int,string> mm;
    m.insert(map<int,string>::value_type(1,"one"));
    m.insert(make_pair(3,"three"));
    m.insert(map<int,string>::value_type(2,"II"));
    m.insert({5,"five"});
    m[4]="four";
    m.insert(pair<int,string>(-1,"minus one"));
    cout << "The size of map is "<<m.size() << endl;
    cout << "for-each loop" << endl;
    for(map<int,string>::value_type p:m)
    {
        cout << "Key="<<p.first<<" Value="<<p.second.c_str() << endl;
    }
    cout << "iterator" << endl;
    cout << m.at(3) << endl;
    m.at(3)="III";
    cout << m.at(3) << endl;
    for (map<int,string>::const_iterator iter=m.begin(); iter!=m.end() ; ++iter )
    {
        cout << "Key="<<iter->first<<" Value="<<iter->second << endl;
    }
    auto iter=m.find(-5);
    if (iter!=m.end())
    {
        cout << "value="<<iter->second << endl;
    }
    else
    {
        cout << "key doesn't exist" << endl;
    }
    if (m.erase(2)>0)
    {
        cout << "2 has been erased successfully!" << endl;
    }
    else
    {
        cout << "failed" << endl;
    }
    mm.insert(map<int,string>::value_type(1,"one"));
    mm.insert(make_pair(1,"I"));
    mm.insert(map<int,string>::value_type(2,"two"));
    mm.insert(map<int,string>::value_type(2,"II"));
    mm.insert(map<int,string>::value_type(2,"2"));
    mm.insert({5,"five"});
    mm.insert(make_pair(5,"V"));
    mm.insert(pair<int,string>(-1,"minus one"));
    cout << "The size of multimap is "<<mm.size() << endl;
    cout << "for-each loop" << endl;
    for(auto p:mm)
    {
        cout << "Key="<<p.first<<" Value="<<p.second.c_str() << endl;
    }
    cout << mm.count(5) << endl;
    mm.erase(mm.lower_bound(1),mm.upper_bound(2));
    for(auto p:mm)
    {
        cout << "Key="<<p.first<<" Value="<<p.second.c_str() << endl;
    }
    return 0;
}
